package org.magicbox.qjunTPO.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.magicbox.qjunTPO.entity.ApplyAll;
import org.magicbox.qjunTPO.mapper.ApplyAllMapper;
import org.magicbox.qjunTPO.service.ApplyAllService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 欢迎添加科技实践队粉丝群：690849711
 * @since 2021-11-17
 */
@Service
public class ApplyAllServiceImpl extends ServiceImpl<ApplyAllMapper, ApplyAll> implements ApplyAllService {

    @Override
    public boolean exApply(ApplyAll applyAll) {
        String applyClass = applyAll.getApplyClass();
        Integer uid = applyAll.getUid();
        Map<String,Object> elMap = new HashMap<>();
        elMap.put("apply_class",applyClass);
        elMap.put("uid",uid);
        try {
            ApplyAll one = getOne(new QueryWrapper<ApplyAll>().allEq(elMap));
            if (one==null) return true;
        }catch (Exception e){
            return false;
        }
        return false;
    }

    @Override
    public IPage getApply(int type, Integer pageNumber, String detial) throws Exception {
        Map<String,String> eqMap = new HashMap<>();
        Page page = new Page(pageNumber,100);
        switch (type){
            case 0:
                break;
            case 1:
                eqMap.put("apply_class","申请入队");
                break;
            case 2:
                eqMap.put("apply_class","申请教室");
                break;
            default:
                throw new Exception();
        }

        eqMap.put("apply_type",detial);
        IPage pageData = page(page,new QueryWrapper<ApplyAll>().allEq(eqMap));
        return pageData;
    }
}
